/**
 * 
 */
package com.study.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import com.study.annotation.anno.SetColumn;
import com.study.annotation.anno.SetTable;
import com.study.annotation.entity.UserTable;

/**
 * @author Administrator
 * @date 2019年4月23日
 */
public class DiySqlTest {

	public static void main(String[] args) throws ClassNotFoundException {
		StringBuffer sb = new StringBuffer("select ");
		/**
		 * 生成Class对象的三种方式
　　1 Class.forName("全路径名") --生成Class对象会初始化类静态块
　　2  类名.Class
　　3 实例对象.getClass()
		 */
		//Class<?> cls = Class.forName("com.study.annotation.entity.UserTable");
		
		//Class cls = UserTable.class;

		UserTable ut = new UserTable();
		Class cls = ut.getClass();
		SetTable table = (SetTable) cls.getAnnotation(SetTable.class);
		
		System.out.println(table.value());
		Field[] declaredFields = cls.getDeclaredFields();
		int len = declaredFields.length;
		for(int i = 0; i < len; i++){
			SetColumn column = declaredFields[i].getAnnotation(SetColumn.class);
			if(i== len -1){
				sb.append(column.value() + " from ");
			}else {
				sb.append(column.value() + ", ");
			}
			//System.out.println(column.value());
		}
		sb.append(table.value());
		System.out.println(sb.toString());
	}
}
